package team.com;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.menu.MenuScene;

public class SceneManager 
{
	private BaseScene _splashScene;
    private BaseScene _menuScene;
    private BaseScene _gameScene;
    private BaseScene _loadingScene;
    private BaseScene _optionsScene;
    //---------------------------------------------
    // VARIABLES
    //---------------------------------------------
    
    private static final SceneManager INSTANCE = new SceneManager();
    
    private SceneType _currentSceneType = SceneType.SCENE_SPLASH;
    
    private BaseScene _currentScene;
    
    private Engine _engine = ResourcesManager.getInstance().engine;
    
    public enum SceneType
    {
        SCENE_SPLASH,
        SCENE_MENU,
        SCENE_GAME,
        SCENE_LOADING,
        SCENE_OPTIONS,
    }
    
    //---------------------------------------------
    // CLASS LOGIC
    //---------------------------------------------
    
    public void setScene(BaseScene scene)
    {
        _engine.setScene(scene);
        _currentScene = scene;
        _currentSceneType = scene.getSceneType();
    }
    
    public void setScene(SceneType sceneType)
    {
        switch (sceneType)
        {
            case SCENE_MENU:
                setScene(_menuScene);
                break;
            case SCENE_GAME:
                setScene(_gameScene);
                break;
            case SCENE_SPLASH:
                setScene(_splashScene);
                break;
            case SCENE_LOADING:
                setScene(_loadingScene);
                break;
            case SCENE_OPTIONS:
            	setScene(_optionsScene);
            	break;
            default:
                break;
        }
    }
    
    public Scene createSplashScene()
    {
    	ResourcesManager.getInstance().loadSplashScene();
    	_splashScene = new SplashScene();
    	setScene(_splashScene);
    	return _splashScene;
    }
    

    public Scene loadGameScene()
    {
    	//doing st
    	ResourcesManager.getInstance().loadGameResources();
    	_gameScene = new GameScene();
    	setScene(_gameScene);
    	return _gameScene;
    }
    

    public Scene createMenuScene()
    {
    	ResourcesManager.getInstance().loadMenuResources();
    	_menuScene = new MainMenuScene();
    	setScene(_menuScene);
    	return _menuScene;
    }
    
    public Scene createOptionsScene()
    {
    	return _optionsScene;
    }

    private void disposeSplashScene()
    {
    	ResourcesManager.getInstance().unLoadSplashScene();
        _splashScene.disposeScene();
        _splashScene = null;
    }
    //---------------------------------------------
    // GETTERS AND SETTERS
    //---------------------------------------------
    
    public static SceneManager getInstance()
    {
        return INSTANCE;
    }
    
    public SceneType getCurrentSceneType()
    {
        return _currentSceneType;
    }
    
    public BaseScene getCurrentScene()
    {
        return _currentScene;
    }
}
